﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.IO;
using System.Net;
using System.Net.Sockets;

namespace Chapter26.TcpSendWithReceive
{
    /// <summary>
    /// TcpSendWindow.xaml 的交互逻辑
    /// </summary>
    public partial class TcpSendWindow : Window
    {
        public TcpSendWindow()
        {
            InitializeComponent();
        }

        private void sendButton_Click(object sender, RoutedEventArgs e)
        {
            var tcpClient = new TcpClient(localhostTextbox.Text, Int32.Parse(portTextBox.Text));
            var networkStream = tcpClient.GetStream();
            var fileStream = File.Open(@"..\..\TcpSendWithReceive\TcpSendWindow.xaml.cs", FileMode.Open);
            var data = fileStream.ReadByte();
            while (data != -1)
            {
                networkStream.WriteByte((byte)data);
                data = fileStream.ReadByte();
            }
            fileStream.Close();
            networkStream.Close();
            tcpClient.Close();
        }
    }
}
